//
//  YJImmediatelygrabViewCell.m
//  SnackCourier
//
//  Created by qianfeng01 on 15/7/21.
//  Copyright (c) 2015年 qianfeng01. All rights reserved.
//

#import "YJImmediatelygrabViewCell.h"
#import "UIImageView+WebCache.h"
#import "YJHeaderController.h"
#import "DBManager.h"


@interface YJImmediatelygrabViewCell ()

@property (nonatomic, assign) BOOL btnStatus; // 状态标识
@property (nonatomic,strong) DBManager *manager;

@end


@implementation YJImmediatelygrabViewCell

- (void)awakeFromNib {
    _manager =[DBManager sharedManager];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    self.contentView.backgroundColor =[UIColor whiteColor];
}

-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
    [super setHighlighted:highlighted animated:animated];
    self.contentView.backgroundColor =[UIColor whiteColor];
}

-(void)showDataWithModel:(YJImmediatelygrabControllerModel *)model controller:(YJBasicinformationController *)BasiView{
    self.model=model;
    self.BasiView=BasiView;
    [self.imgUrlimageView  sd_setImageWithURL:[NSURL URLWithString:model.imgUrl]];
    self.titleLabel.text =model.title;
    if (model.originalPrice.length!=0) {
        self.originalPriceLabel.text=[NSString stringWithFormat:@"￥：%@",model.originalPrice];
    }else{
        self.originalPriceLabel.text=@"";
    }
    
    self.priceLabel.text =[NSString stringWithFormat:@"￥：%@",model.price];
    self.salesVolume.text =[NSString stringWithFormat:@"销量%ld",model.salesVolume];
    [self.shoucangButton setBackgroundImage:[UIImage imageNamed:@"detail_collect"] forState:(UIControlStateNormal)];
    self.btnStatus =YES;
    [self.gogobutton setBackgroundImage:[UIImage imageNamed:@"longBtnBG"] forState:(UIControlStateNormal)];
    [self.gogobutton setBackgroundImage:[UIImage imageNamed:@"longBtnBG"] forState:(UIControlStateSelected)];
    [self.gogobutton setTitle:[NSString stringWithFormat:@"去%@购买",model.website] forState:(UIControlStateNormal)];
    
    
}
- (IBAction)shoucangClick:(id)sender {
    if (self.btnStatus ==NO) {
        [self.shoucangButton setBackgroundImage:[UIImage imageNamed:@"detail_collect"] forState:(UIControlStateNormal)];
        [_manager deleteModelForId:self.model.id];
    }else{
        [self.shoucangButton setBackgroundImage:[UIImage imageNamed:@"detail_collect_HL"] forState:(UIControlStateNormal)];
        [_manager insertModel:self.model];
    }
    self.btnStatus =!self.btnStatus;
}

- (IBAction)GogoClick:(id)sender {
    YJHeaderController *controller =[[YJHeaderController alloc] init];
    controller.linkUrl =self.model.linkUrl;
    [self.BasiView.navigationController pushViewController:controller animated:YES]; 
}


@end
